<!DOCTYPE html>






  


<html class="theme-next mist use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">



  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">




  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />










  <meta name="baidu-site-verification" content="6hi01gkdPQ" />










  
  
  
  

  
    
    
  

  
    
      
    

    
  

  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic|Roboto Slab:300,300italic,400,400italic,700,700italic|Lobster Two:300,300italic,400,400italic,700,700italic|PT Mono:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.2.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.ico?v=6.2.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.ico?v=6.2.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.ico?v=6.2.0">


  <link rel="mask-icon" href="/images/logo.ico?v=6.2.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '6.2.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '995B6MOVEJ',
      apiKey: 'cc928ef862522d7631d991ac65f2ec92',
      indexName: 'imwangyu',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="CGLIB和Java动态代理的区别 Java动态代理只能够对接口进行代理，不能对普通的类进行代理（因为所有生成的代理类的父类为Proxy，Java类继承机制不允许多重继承）；CGLIB能够代理普通类； Java动态代理使用Java原生的反射API进行操作，在生成类上比较高效；CGLIB使用ASM框架直接对字节码进行操作，在类的执行过程中比较高效  锁synchronized同步代码块 使用字节码指">
<meta name="keywords" content="Java,知识点">
<meta property="og:type" content="article">
<meta property="og:title" content="Java相关知识点">
<meta property="og:url" content="http://wyu.space/2018/05/02/Java相关知识点/index.html">
<meta property="og:site_name" content="Sometimes Naive">
<meta property="og:description" content="CGLIB和Java动态代理的区别 Java动态代理只能够对接口进行代理，不能对普通的类进行代理（因为所有生成的代理类的父类为Proxy，Java类继承机制不允许多重继承）；CGLIB能够代理普通类； Java动态代理使用Java原生的反射API进行操作，在生成类上比较高效；CGLIB使用ASM框架直接对字节码进行操作，在类的执行过程中比较高效  锁synchronized同步代码块 使用字节码指">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/54561571.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/58571706.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/7892250.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/11437042.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/12960615.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/71246092.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/55279777.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/57832256.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/20882052.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/49640930.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/35826754.jpg">
<meta property="og:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/1366019.jpg">
<meta property="og:updated_time" content="2018-05-02T15:36:35.380Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java相关知识点">
<meta name="twitter:description" content="CGLIB和Java动态代理的区别 Java动态代理只能够对接口进行代理，不能对普通的类进行代理（因为所有生成的代理类的父类为Proxy，Java类继承机制不允许多重继承）；CGLIB能够代理普通类； Java动态代理使用Java原生的反射API进行操作，在生成类上比较高效；CGLIB使用ASM框架直接对字节码进行操作，在类的执行过程中比较高效  锁synchronized同步代码块 使用字节码指">
<meta name="twitter:image" content="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/54561571.jpg">



  <link rel="alternate" href="/atom.xml" title="Sometimes Naive" type="application/atom+xml" />




  <link rel="canonical" href="http://wyu.space/2018/05/02/Java相关知识点/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>Java相关知识点 | Sometimes Naive</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?405d001d8bd35d058cc9251901c71aa6";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
	
	<a href="https://github.com/imwangyu"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
	
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Sometimes Naive</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>




<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-about">
    <a href="/about/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-commonweal">
    <a href="/404.html" rel="section">
      <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />公益 404</a>
  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  
    

  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  
    <div class="reading-progress-bar"></div>
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://wyu.space/2018/05/02/Java相关知识点/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="王宇">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Sometimes Naive">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java相关知识点
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-05-02 01:11:55 / 修改时间：23:36:35" itemprop="dateCreated datePublished" datetime="2018-05-02T01:11:55+08:00">2018-05-02</time>
            

            
              

              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="post-meta-item-icon"
            >
            <i class="fa fa-eye"></i>
             热度： 
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
			<span>℃</span>
            </span>
          

          
            <div class="post-symbolscount">
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">本文字数：</span>
                
                <span title="本文字数">5.4k</span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">5 分钟</span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="CGLIB和Java动态代理的区别"><a href="#CGLIB和Java动态代理的区别" class="headerlink" title="CGLIB和Java动态代理的区别"></a>CGLIB和Java动态代理的区别</h1><ol>
<li>Java动态代理只能够对接口进行代理，不能对普通的类进行代理（因为所有生成的代理类的父类为Proxy，Java类继承机制不允许多重继承）；CGLIB能够代理普通类；</li>
<li>Java动态代理使用Java原生的反射API进行操作，在生成类上比较高效；CGLIB使用ASM框架直接对字节码进行操作，在类的执行过程中比较高效</li>
</ol>
<h1 id="锁"><a href="#锁" class="headerlink" title="锁"></a>锁</h1><h2 id="synchronized"><a href="#synchronized" class="headerlink" title="synchronized"></a>synchronized</h2><p>同步代码块 使用字节码指令 monitorenter monitorexit(一次只能一个进入)</p>
<p>同步方法 ACC_synchronized标志位</p>
<h2 id="volatile"><a href="#volatile" class="headerlink" title="volatile"></a>volatile</h2><ol>
<li>保证多线程共享变量可见性</li>
<li>禁止指令重排序</li>
<li>不保证原子性</li>
</ol>
<p>直接写入主内存，不写入本地内存</p>
<h3 id="不保证原子性"><a href="#不保证原子性" class="headerlink" title="不保证原子性"></a>不保证原子性</h3><p>在volatile变量前加上lock汇编指令</p>
<ol>
<li>重排序时不能把后面的指令重排序到内存屏障之前的位置</li>
<li>使得本CPU的Cache写入内存(相当于直接写入主内存)</li>
<li>写入动作也会引起别的CPU或者别的内核无效化其Cache(读取的时候去主内存读取)，相当于让新写入的值对别的线程可见。</li>
</ol>
<p>用处：</p>
<ol>
<li>多线程共享变量只读操作。根据只读变量当做标志位。</li>
<li>防止重排序<h2 id="CAS算法"><a href="#CAS算法" class="headerlink" title="CAS算法"></a>CAS算法</h2>使用处理器指令CMPXCHG</li>
</ol>
<p>自旋CAS：不断地获取，直到成功</p>
<h2 id="线程通讯"><a href="#线程通讯" class="headerlink" title="线程通讯"></a>线程通讯</h2><ol>
<li>wait,notify这类方法是定义在Object上的。</li>
<li>调用wait或者notify时必须首先通过synchronized关键字获取到对象的锁。</li>
<li>调用wait方法时会释放锁。调用notify时不会释放锁，代码走完才会释放锁。</li>
<li>join方法内部使用wait.join方法可以实现简单的线程等待。</li>
<li>wait和sleep遇到interrupt会抛出异常。</li>
<li>ThreadLocal保存线程隔离数据。</li>
</ol>
<p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/54561571.jpg" alt=""></p>
<ol>
<li>一个对象拥有一个等待队列和同步队列</li>
<li>synchronized锁的对象一致才会互斥。</li>
</ol>
<h2 id="Lock和AQS"><a href="#Lock和AQS" class="headerlink" title="Lock和AQS"></a>Lock和AQS</h2><p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/58571706.jpg" alt=""></p>
<h3 id="独占锁流程"><a href="#独占锁流程" class="headerlink" title="独占锁流程"></a>独占锁流程</h3><p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/7892250.jpg" alt=""></p>
<h3 id="共享锁流程"><a href="#共享锁流程" class="headerlink" title="共享锁流程"></a>共享锁流程</h3><ol>
<li>入队列：线程获取锁失败后，创建一个节点，并将节点添加到等待队列尾，然后将线程阻塞，等待唤醒；</li>
<li>唤醒：另一个线程释放锁，取队列的第一个节点，将节点对应线程唤醒；</li>
<li>出队列：唤醒后的线程将尝试获取锁，成功后将自己移出队列，同时判断是否任然存在空闲的锁，如果存在则继续唤醒下一个节点。</li>
<li>每次只会唤醒第一个节点，如果同时释放多个锁，后续的节点将由前面被唤醒的节点来唤醒，尽量减少数据竞争。</li>
</ol>
<h2 id="ReentrantLock"><a href="#ReentrantLock" class="headerlink" title="ReentrantLock"></a>ReentrantLock</h2><p>独占的可重入锁</p>
<figure class="highlight aspectj"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">final</span> <span class="function"><span class="keyword">boolean</span> <span class="title">nonfairTryAcquire</span><span class="params">(<span class="keyword">int</span> acquires)</span> </span>&#123;</div><div class="line">  <span class="keyword">final</span> Thread current = Thread.currentThread();</div><div class="line">  <span class="keyword">int</span> c = getState();</div><div class="line">  <span class="keyword">if</span> (c == <span class="number">0</span>) &#123;</div><div class="line">    <span class="keyword">if</span> (compareAndSetState(<span class="number">0</span>, acquires)) &#123;</div><div class="line">      setExclusiveOwnerThread(current);</div><div class="line">      <span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">    &#125;</div><div class="line">  &#125;</div><div class="line">  <span class="comment">//说白了，就是在这里！判断下获取锁的线程是否为当前线程，如果是，直接让state+1</span></div><div class="line">  <span class="keyword">else</span> <span class="keyword">if</span> (current == getExclusiveOwnerThread()) &#123;</div><div class="line">    <span class="keyword">int</span> nextc = c + acquires;</div><div class="line">    <span class="keyword">if</span> (nextc &lt; <span class="number">0</span>) <span class="comment">// overflow</span></div><div class="line">      <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">"Maximum lock count exceeded"</span>);</div><div class="line">      setState(nextc);</div><div class="line">      <span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>当头结点刚释放锁时候，假如这时候有一个线程调用的lock方法想要获取锁，那么他相对于队列中的线程就是不公平的</p>
<h2 id="ReentrantReadWriteLock"><a href="#ReentrantReadWriteLock" class="headerlink" title="ReentrantReadWriteLock"></a>ReentrantReadWriteLock</h2><ol>
<li>内部维护了两个Lock，一个ReadLock，一个WriteLock。</li>
<li>读锁是一个可重入的共享锁。写锁是一个可重入的独占锁。</li>
<li>内部维护时讲state变量分为高16位和低16位来操作。</li>
<li>读锁与写锁相互排斥 。比如在获取读锁时如果已经有写锁了，阻塞。反之亦然。</li>
</ol>
<h2 id="LockSupport"><a href="#LockSupport" class="headerlink" title="LockSupport"></a>LockSupport</h2><p>阻塞线程使用LockSupport工具类实现</p>
<p>monitorenter指令加上去之后线程切换上去之后发现没有进入又直接切换走。而LockSupport的park方法则是将线程休息，此时线程处于WAITING状态。CPU是不会切换上去的。这就大大减少了线程的上下文切换。</p>
<h1 id="Condition线程通讯"><a href="#Condition线程通讯" class="headerlink" title="Condition线程通讯"></a>Condition线程通讯</h1><p>Condition底层的线程等待也是使用的LockSupport的park方法。它对interrupt方法不敏感，而wait方法遇到interrupt就抛异常</p>
<p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/11437042.jpg" alt=""></p>
<p>await方法，其实就是先释放锁(说白了底层就是更改了AQS的state),然后调用LockSupport的park方法park自己，再把自己丢进Condition的等待队列中。这里不要忘记了，释放锁的同时还通知了同步队列中的线程去拿锁哦。</p>
<p>signal方法其实就是将Condition等待队列中的线程移动到同步队列。至于它拿不拿的到锁，还是另外一回事。</p>
<h2 id="Condition底层模型"><a href="#Condition底层模型" class="headerlink" title="Condition底层模型"></a>Condition底层模型</h2><p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/12960615.jpg" alt=""></p>
<p>调用await()<br><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/71246092.jpg" alt=""></p>
<p>调用signal()</p>
<p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/55279777.jpg" alt=""></p>
<h1 id="容器"><a href="#容器" class="headerlink" title="容器"></a>容器</h1><h2 id="HashMap"><a href="#HashMap" class="headerlink" title="HashMap"></a>HashMap</h2><h3 id="底层"><a href="#底层" class="headerlink" title="底层"></a>底层</h3><p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/57832256.jpg" alt=""></p>
<p>为什么HashMap在扩容时数组的长度必须是2的倍数(默认16)，其实这和indexFor()这个方法有关系的，这个方法是根据key的hash值算出在数组对应的索引</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">int</span> <span class="title">indexFor</span><span class="params">(<span class="keyword">int</span> h, <span class="keyword">int</span> length)</span> </span>&#123;</div><div class="line">    <span class="keyword">return</span> h &amp; (length<span class="number">-1</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>h &amp; (length-1)要和h%length的效果一样就必须保证length的长度是2的倍数</p>
<h3 id="扩容相关-容量，负载因子，2的倍数"><a href="#扩容相关-容量，负载因子，2的倍数" class="headerlink" title="扩容相关(容量，负载因子，2的倍数)"></a>扩容相关(容量，负载因子，2的倍数)</h3><p>数组的默认长度是16</p>
<p>原数组中的数据必须重新计算其在新数组中的位置，并放进去，这就是 resize</p>
<p>HashMap 中的元素个数超过(数组大小 *XloadFactor)时，就会进行数组扩容，loadFactor的默认值为 0.75，这是一个折中的取值</p>
<h2 id="ArrayList"><a href="#ArrayList" class="headerlink" title="ArrayList"></a>ArrayList</h2><h3 id="扩容"><a href="#扩容" class="headerlink" title="扩容"></a>扩容</h3><p>每当向数组中添加元素时，都要去检查添加后元素的个数是否会超出当前数组的长度，如果超出，数组将会进行扩容，以满足添加数据的需求。数组扩容有两个方法，其中开发者可以通过一个 public 的方法ensureCapacity(int minCapacity)来增加 ArrayList 的容量，而在存储元素等操作过程中，如果遇到容量不足，会调用priavte方法private void ensureCapacityInternal(int minCapacity)实现。</p>
<figure class="highlight ruby"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">int newCapacity = oldCapacity + (oldCapacity <span class="meta">&gt;&gt; </span><span class="number">1</span>)</div></pre></td></tr></table></figure>
<p>1.5倍</p>
<p>Arrays.copyOf方法:</p>
<p>根据newLength创建了一个数组，然后调用System.arraycopy把数据拷贝了过去。这个System.arraycopy又是个native方法，据说速度很快</p>
<h2 id="继承关系"><a href="#继承关系" class="headerlink" title="继承关系"></a>继承关系</h2><p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/20882052.jpg" alt=""></p>
<p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/49640930.jpg" alt=""></p>
<figure class="highlight armasm"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="symbol">Map</span> <span class="meta">map</span> = new HashMap()<span class="comment">;</span></div><div class="line">    <span class="keyword">Iterator </span><span class="keyword">iter </span>= <span class="meta">map</span>.entrySet().<span class="keyword">iterator();</span></div><div class="line"><span class="keyword"> </span>   <span class="meta">while</span> (<span class="keyword">iter.hasNext()) </span>&#123;</div><div class="line">        <span class="meta">Map</span>.Entry <span class="meta">entry</span> = (<span class="meta">Map</span>.Entry) <span class="keyword">iter.next();</span></div><div class="line"><span class="keyword"> </span>       Object key = <span class="meta">entry</span>.getKey()<span class="comment">;</span></div><div class="line">        Object val = <span class="meta">entry</span>.getValue()<span class="comment">;</span></div><div class="line">    &#125;</div></pre></td></tr></table></figure>
<figure class="highlight processing"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">Map <span class="built_in">map</span> = <span class="keyword">new</span> <span class="keyword">HashMap</span>();</div><div class="line">Iterator iter = <span class="built_in">map</span>.keySet().iterator();</div><div class="line">    <span class="keyword">while</span> (iter.hasNext()) &#123;</div><div class="line">    <span class="keyword">Object</span> <span class="built_in">key</span> = iter.next();</div><div class="line">    <span class="keyword">Object</span> val = <span class="built_in">map</span>.<span class="built_in">get</span>(<span class="built_in">key</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>第一种快</p>
<p>在使用Iterable遍历Collection时，当Collection内部的元素为对象类型时，.next返回的是指针。也就是说是浅拷贝。</p>
<p>集合与集合之间的转换<br>Map–》Collection：<br><figure class="highlight less"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="selector-tag">Map</span><span class="selector-class">.keySet</span>(),<span class="selector-tag">entrySet</span>(),<span class="selector-class">.values</span>().三个<span class="selector-tag">API</span></div></pre></td></tr></table></figure></p>
<p>List《—》Set《—》Queue:<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">//<span class="keyword">Set</span><span class="comment">--》List</span></div><div class="line"><span class="keyword">List</span>&lt;<span class="keyword">String</span>&gt; list3 = <span class="keyword">new</span> ArrayList&lt;<span class="keyword">String</span>&gt;(<span class="keyword">new</span> HashSet&lt;<span class="keyword">String</span>&gt;());</div><div class="line">//List<span class="comment">--》Set</span></div><div class="line"><span class="keyword">Set</span>&lt;<span class="keyword">String</span>&gt; <span class="keyword">set</span> = <span class="keyword">new</span> HashSet&lt;<span class="keyword">String</span>&gt;(<span class="keyword">new</span> ArrayList&lt;<span class="keyword">String</span>&gt;());</div></pre></td></tr></table></figure></p>
<h2 id="LinkedList"><a href="#LinkedList" class="headerlink" title="LinkedList"></a>LinkedList</h2><p>双向链表</p>
<figure class="highlight axapta"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="keyword">void</span> add(<span class="keyword">int</span> <span class="keyword">index</span>, E element) &#123;</div><div class="line">    checkPositionIndex(<span class="keyword">index</span>);</div><div class="line">    <span class="keyword">if</span> (<span class="keyword">index</span> == size)</div><div class="line">        <span class="comment">//链表尾部添加element</span></div><div class="line">        linkLast(element);</div><div class="line">    <span class="keyword">else</span></div><div class="line">        在某个元素前面添加element</div><div class="line">        linkBefore(element, node(<span class="keyword">index</span>));</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="keyword">public</span> E get(<span class="keyword">int</span> <span class="keyword">index</span>) &#123;</div><div class="line">    checkElementIndex(<span class="keyword">index</span>);</div><div class="line">    <span class="keyword">return</span> node(<span class="keyword">index</span>).item;</div><div class="line">&#125;</div><div class="line"></div><div class="line">    Node&lt;E&gt; node(<span class="keyword">int</span> <span class="keyword">index</span>) &#123;</div><div class="line">    <span class="comment">// assert isElementIndex(index);</span></div><div class="line"></div><div class="line">    <span class="keyword">if</span> (<span class="keyword">index</span> &lt; (size &gt;&gt; <span class="number">1</span>)) &#123;</div><div class="line">        Node&lt;E&gt; x = first;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="keyword">index</span>; i++)</div><div class="line">            x = x.next;</div><div class="line">        <span class="keyword">return</span> x;</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">        Node&lt;E&gt; x = last;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = size - <span class="number">1</span>; i &gt; <span class="keyword">index</span>; i--)</div><div class="line">            x = x.prev;</div><div class="line">        <span class="keyword">return</span> x;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>根据索引拿到Node后，其他的就是链表的基本操作了，新增和删除的时候其实都只会影响某个Node的前后节点，挪一挪指针就OK了。</p>
<h2 id="LinkedHashMap"><a href="#LinkedHashMap" class="headerlink" title="LinkedHashMap"></a>LinkedHashMap</h2><p>在使用上，LinkedHashMap和HashMap的区别就是LinkedHashMap是有序的</p>
<h3 id="原理"><a href="#原理" class="headerlink" title="原理"></a>原理</h3><p>LinkedHashMap继承自HashMap,它的新增(put)和获取(get)方法都是复用父类的HashMap的代码，只是自己重写了put给get内部的某些接口来搞事情，这个特性在C++中叫钩子技术，在Java里面大家喜欢叫多态，其实多态这个词并不能很好的形容这种现象。</p>
<p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/35826754.jpg" alt=""></p>
<p><img src="http://p1k0tu9ph.bkt.clouddn.com/18-3-7/1366019.jpg" alt=""></p>
<figure class="highlight scala"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">private</span> static <span class="class"><span class="keyword">class</span> <span class="title">Entry&lt;K</span>,<span class="title">V&gt;</span> <span class="keyword">extends</span> <span class="title">HashMap</span>.<span class="title">Entry&lt;K</span>,<span class="title">V&gt;</span> </span>&#123;</div><div class="line">    <span class="comment">// These fields comprise the doubly linked list used for iteration.</span></div><div class="line">    <span class="type">Entry</span>&lt;<span class="type">K</span>,<span class="type">V</span>&gt; before, after;</div><div class="line"></div><div class="line"><span class="type">Entry</span>(int hash, <span class="type">K</span> key, <span class="type">V</span> value, <span class="type">HashMap</span>.<span class="type">Entry</span>&lt;<span class="type">K</span>,<span class="type">V</span>&gt; next) &#123;</div><div class="line">        <span class="keyword">super</span>(hash, key, value, next);</div><div class="line">    &#125;</div><div class="line">    ...</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>前面四个，是从HashMap.Entry中继承过来的；后面两个，是是LinkedHashMap独有的。不要搞错了next和before、After，next是用于维护HashMap指定table位置上连接的Entry的顺序的，before、After是用于维护Entry插入的先后顺序的(为了维护双向链表)。</p>
<h3 id="利用LinkedHashMap实现LRU缓存"><a href="#利用LinkedHashMap实现LRU缓存" class="headerlink" title="利用LinkedHashMap实现LRU缓存"></a>利用LinkedHashMap实现LRU缓存</h3>
      
    </div>

    
	
	<div>
      
      <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
      
    </div>

    
    
    
	
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="王宇 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="王宇 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>王宇</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://wyu.space/2018/05/02/Java相关知识点/" title="Java相关知识点">http://wyu.space/2018/05/02/Java相关知识点/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
          
            <a href="/tags/知识点/" rel="tag"><i class="fa fa-tag"></i> 知识点</a>
          
        </div>
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div id="needsharebutton-postbottom">
            <span class="btn">
              <i class="fa fa-share-alt" aria-hidden="true"></i>
            </span>
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/05/02/MySQL相关知识点/" rel="next" title="MySQL相关知识点">
                <i class="fa fa-chevron-left"></i> MySQL相关知识点
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/05/02/Linux基本操作/" rel="prev" title="Linux基本操作">
                Linux基本操作 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNjE0NS8xMjY4MA=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="王宇" />
            
              <p class="site-author-name" itemprop="name">王宇</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">10</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">7</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">18</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://wangshifu.net.cn" title="Wong" target="_blank">Wong</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://pvitlzp.cn" title="刘志鹏" target="_blank">刘志鹏</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#CGLIB和Java动态代理的区别"><span class="nav-number">1.</span> <span class="nav-text">CGLIB和Java动态代理的区别</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#锁"><span class="nav-number">2.</span> <span class="nav-text">锁</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#synchronized"><span class="nav-number">2.1.</span> <span class="nav-text">synchronized</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#volatile"><span class="nav-number">2.2.</span> <span class="nav-text">volatile</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#不保证原子性"><span class="nav-number">2.2.1.</span> <span class="nav-text">不保证原子性</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#CAS算法"><span class="nav-number">2.3.</span> <span class="nav-text">CAS算法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#线程通讯"><span class="nav-number">2.4.</span> <span class="nav-text">线程通讯</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Lock和AQS"><span class="nav-number">2.5.</span> <span class="nav-text">Lock和AQS</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#独占锁流程"><span class="nav-number">2.5.1.</span> <span class="nav-text">独占锁流程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#共享锁流程"><span class="nav-number">2.5.2.</span> <span class="nav-text">共享锁流程</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ReentrantLock"><span class="nav-number">2.6.</span> <span class="nav-text">ReentrantLock</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ReentrantReadWriteLock"><span class="nav-number">2.7.</span> <span class="nav-text">ReentrantReadWriteLock</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#LockSupport"><span class="nav-number">2.8.</span> <span class="nav-text">LockSupport</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Condition线程通讯"><span class="nav-number">3.</span> <span class="nav-text">Condition线程通讯</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Condition底层模型"><span class="nav-number">3.1.</span> <span class="nav-text">Condition底层模型</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#容器"><span class="nav-number">4.</span> <span class="nav-text">容器</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#HashMap"><span class="nav-number">4.1.</span> <span class="nav-text">HashMap</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#底层"><span class="nav-number">4.1.1.</span> <span class="nav-text">底层</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#扩容相关-容量，负载因子，2的倍数"><span class="nav-number">4.1.2.</span> <span class="nav-text">扩容相关(容量，负载因子，2的倍数)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ArrayList"><span class="nav-number">4.2.</span> <span class="nav-text">ArrayList</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#扩容"><span class="nav-number">4.2.1.</span> <span class="nav-text">扩容</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#继承关系"><span class="nav-number">4.3.</span> <span class="nav-text">继承关系</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#LinkedList"><span class="nav-number">4.4.</span> <span class="nav-text">LinkedList</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#LinkedHashMap"><span class="nav-number">4.5.</span> <span class="nav-text">LinkedHashMap</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#原理"><span class="nav-number">4.5.1.</span> <span class="nav-text">原理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#利用LinkedHashMap实现LRU缓存"><span class="nav-number">4.5.2.</span> <span class="nav-text">利用LinkedHashMap实现LRU缓存</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">王宇</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">站点总字数：</span>
    
    <span title="站点总字数">29k</span>
  

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    
    <span title="站点阅读时长">26 分钟</span>
  
</div>




  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动 v3.3.8</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/theme-next/hexo-theme-next">NexT.Mist</a> v6.2.0</div>



        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv" title="总访客量">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="site-pv" title="总访问量">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
      <div id="needsharebutton-float">
        <span class="btn">
          <i class="fa fa-share-alt" aria-hidden="true"></i>
        </span>
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>














  











  



  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/reading_progress/reading_progress.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.2.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.2.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.2.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.2.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.2.0"></script>



  



	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  










  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=6.2.0"></script>



  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  
  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
      pbOptions = {};
      
          pbOptions.iconStyle = "box";
      
          pbOptions.boxForm = "horizontal";
      
          pbOptions.position = "bottomCenter";
      
          pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-postbottom', pbOptions);
    
    
      flOptions = {};
      
          flOptions.iconStyle = "box";
      
          flOptions.boxForm = "horizontal";
      
          flOptions.position = "bottomLeft";
      
          flOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-float', flOptions);
    
  </script>

  

  

  

  

  
  
  
  <script src="/lib/bookmark/bookmark.min.js?v=1.0"></script>
  <script type="text/javascript">
  
    bookmark.scrollToMark('auto', "#更多");
  
  </script>


  

  
  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/src/love.js"></script>
</body>
</html>
